#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
#include<cctype>
using namespace std;
class CTelNumber {
private:
	char* p;
public:
	CTelNumber() {
		char* p1 = new char[9];
		p = p1;
		cin >> p;
		int len = strlen(p);
		p[len] = 0;
 	}
	CTelNumber(const CTelNumber& c) {
		char* p1 = new char[9];
		p = p1;
		p[8] = 0;
		if (strlen(c.p) != 7) {
			cout << "Illegal phone number" << endl;
			goto A;
		}
		strcpy(p + 1, c.p);
		for (int i = 1; i < 8; i++) {
			if (isdigit(p[i]) == false) {
				cout << "Illegal phone number" << endl;
				goto A;
			}
		}
		if (p[1] >= '2' && p[1] <= '4') {
			p[0] = '8';
		}
		else if(p[1] >= '5' && p[1] <= '8') {
			p[0] = '2';
		}
		else {
			cout << "Illegal phone number" << endl;
			goto A;
		}
		cout << p << endl;
	A:;
	}
	~CTelNumber() {
		delete[] p;
	}
};
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		CTelNumber a;
		CTelNumber b(a);
	}
	return 0;
}